package com.sinaapp.gavinzhang.second;

import org.junit.Test;

/**
 * 查找变位词
 * Created by gavin on 15-8-7.
 */
public class ParityWord {

    @Test
    public void findParityWord()
    {
        String[] strings = {"test","pot","top","stop","area","stet"};


        //对数据进行处理
        String[] tmp = new String[strings.length];
        for (int i = 0; i < strings.length; i++) {
            StringBuilder sb = new StringBuilder();
            for (char j = 'a'; j <= 'z'; j++) {
                int num = 0;
                for (int k = 0; k < strings[i].length(); k++) {
                    if (strings[i].charAt(k) == j)
                    {
                        num++;
                    }
                }
                sb.append(j);
                sb.append(num);
            }
            tmp[i] = sb.toString();
        }

        //查找数据
        for (int i = 0; i < tmp.length; i++) {
            if (tmp[i].length()!=0)
            {
                System.out.print(strings[i]+" ");
            }else {
                continue;
            }

            for (int j = i+1; j < tmp.length; j++) {
                if (tmp[i].equals(tmp[j]))
                {
                    System.out.print(strings[j]);
                    tmp[j] = "";
                }
            }
            System.out.println();
        }

    }
}
